package cn.tedu.weibo.common.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    //响应状态码[内部业务状态码]:例如 1000
    private Integer code;
    //状态码的含义：例如 未登录
    private String msg;
    //响应具体数据
    private Object data;

    /**
     * 第一个构造方法：之封装状态码和提示信息，针对不需要返回具体数据的这一类控制器方法[功能]
     */
    public JsonResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    public JsonResult(StatusCode statusCode){
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
    }
    public JsonResult(StatusCode statusCode,Object data){
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
        //上面两句等价于 this(statusCode);
        this.data = data;
    }
/**
 * 第四个构造方法
 */
 public JsonResult(Object data){
     this.code = StatusCode.SUCCESS.getCode();
     this.msg = StatusCode.SUCCESS.getMsg();
     this.data = data;
 }
    /**
     * 静态方法：1.
     */
    public static JsonResult ok (Object data){
     return new JsonResult(data);
    }
    /**
     * 静态方法：2.
     */
    public static JsonResult ok (){
        return ok(null);
    }



}
